var _as = {

    checkbox: function() { // 复选框样式
        $('.sys-content input[type="checkbox"]').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        });
    },
    scrollbar: function() {
        // $(".scrollbar").mCustomScrollbar({
        //     scrollButtons:{
        //         enable:true
        //     }
        // });
    },
    btnOk: function(callback, obj) {
        startDrag(document.getElementById('jacBar'), document.getElementById('jacBox'));
        $("#jOk").click(function() {
            $("#jac").remove();
            if (typeof(callback) == 'function') {
                callback(obj);
            }
        });
    },
    btnNo: function() {
        $("#jNo,#jacClose").click(function() {
            $("#jac").remove();
            $("div.wrap").find("#loading").hide();
        });
    },
    jMaxLength: function(data) {
        var p = data.split("</p>"),
            l = 0;
        for (var i in p) {
            var ll = p[i].length;
            if (ll > l) {
                l = ll;
            }
        }
        l = l * 1.2;
        $("#jac .modal-dialog").css("width", l + "%"); // 动态设置弹出层宽度
        $("#jac #jacBox").css("left", ((1 - l / 100) / 2 * 100) + "%"); // 动态设置弹出层居中显示
    },
    jAlertTmpl:'scripts/plugins/jac.tmpl',
    jAlert: function(data, callback, obj,tmppurl) {
        if(!tmppurl)tmppurl=this.jAlertTmpl;
        $.get(tmppurl, function(tmpl) {
            $("#jac").remove();
            $('body').append(tmpl);
            $("#jNo").hide();
            _as.jMaxLength(data);
           _as.btnOk(callback, obj);
            _as.btnNo();
            $("#jac").find("#jacMessage").append(data);
        })
    },
    jConfirm: function(data, callback, obj,tmppurl) {
        if(!tmppurl)tmppurl='scripts/plugins/jac.tmpl'
        $.get(tmppurl, function(tmpl) {
            $("#jac").remove();
            $('body').append($.tmpl(tmpl, data));
            _as.jMaxLength(data);
            _as.btnOk(callback, obj);
            _as.btnNo();
            $("#jac").find("#jacMessage").append(data);
        })
    },
    shake: function(e, oncomplete, distance, time, onoff) {
        var ee = e;
        if (typeof e === "string") e = document.getElementById(e);
        if (!distance) distance = 5;
        if (!time) time = 500;
        var originalStyle = e.style.cssText;
        e.style.position = "relative";
        var start = (new Date()).getTime();
        if (onoff == "noShowRed") {
            $("#" + ee).css("background-color", "#f10000").focus();
            // e.style.backgroundColor = "#f10000";
        } else {
            $("table").find("div").css("background-color", "#f10000");
        }
        animate();

        function animate() {
            var now = (new Date()).getTime();
            var elapsed = now - start;
            var fraction = elapsed / time;
            if (fraction < 1) {
                var x = distance * Math.sin(fraction * 4 * Math.PI);
                e.style.left = x + "px";
                setTimeout(animate, Math.min(25, time - elapsed));
            } else {
                e.style.cssText = originalStyle;
                if (oncomplete) oncomplete(e);
            }
        }
    },
    fadeOut: function(e, oncomplete, time) {
        if (typeof e === "string") e = document.getElementById(e);
        if (!time) time = 500;
        var ease = Math.sqrt;
        var originalStyle = e.style.cssText;

        var start = (new Date()).getTime();
        animate();

        function animate() {
            var elapsed = (new Date()).getTime() - start;
            var fraction = elapsed / time;
            if (fraction < 1) {
                var opacity = 1 - ease(fraction);
                e.style.opacity = String(opacity);
                setTimeout(animate, Math.min(25, time - elapsed));
            } else {
                // e.style.opacity = "0";
                e.style.cssText = originalStyle;
                $("table").find("div").css("background-color", "");
                if (oncomplete) oncomplete(e);
            }
        }
    },
    maxL: function(dom, maxL) {
        $("table").one("webkitAnimationEnd", "tr", function() {
            $("table").find("tr").removeClass('slideInRight');
        })
        $('[data-toggle="tooltip"]').tooltip();
        $(dom).find("span.maxL").each(function(index, el) {
            var $this = $(this),
                text = $this.attr("data-original-title");
            if (text.length > maxL) {
                text = text.substr(0, maxL);
                $this.text(text + "...").css("cursor", "help");
            } else {
                $this.parents("td").empty().text(text);
            }
        });
    },
    maxLe: function(dom, maxL) {
        $("table").one("webkitAnimationEnd", "tr", function() {
            $("table").find("tr").removeClass('slideInRight');
        })
        $('[data-toggle="tooltip"]').tooltip();
        $(dom).find("span.maxL").each(function(index, el) {
            var $this = $(this),
                text = $this.attr("data-original-title");
            if (text.length > maxL) {
                text = text.substr(0, maxL);
                $this.text(text + "...").css("cursor", "help");
            } else {
                $this.empty().text(text);
            }
        });
    },
    clickOften: function() {
        if (parseInt(sessionStorage.clickOften)) {
            sessionStorage.clickOften = 0;
            setTimeout(function() {
                sessionStorage.clickOften = 1;
            }, 1500);
            return false;
        } else {
            // _as.jAlert("<p>非法操作：频繁请求！</p>");
            return true;
        }
    },



}

$(function() {
    //select style
    $(".chosen-select").chosen(); //不显示搜索框 {disable_search:true}

    // 弹出层事件
    $('[data-toggle="popover"]').popover();
    $('[data-toggle="tooltip"]').tooltip();

    $(".check-radio").on("click", "li", function() {
        $(this).siblings().removeClass('active').end().addClass('active');
    });
    $(".check-toggle").on("click", "li", function() {
        $(this).hasClass('active') ? $(this).removeClass('active') : $(this).addClass('active');
    });

    _as.checkbox();
})